package com.example.WebTask1.Dao;

import com.example.WebTask1.Until.DbUntil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImp implements UserDao{
    @Override
    public Boolean queryUserAndPwd(String name,String pwd) {
        Connection connection = null;
        try {
            System.out.println("数据库连接");
            System.out.println("----"+name+pwd);
            connection = DbUntil.getConnection();

            String sql = "SELECT * FROM register WHERE `name`=? AND `password`=? ";

            PreparedStatement preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setString(1, name);
            preparedStatement.setString(2, pwd);

            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                return true;
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
            return false;
    }
}
